package com.paotui.controller;

import cn.hutool.json.JSONUtil;
import com.paotui.common.R;
import com.paotui.pojo.Users_address;
import com.paotui.service.impl.UsersAddressServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/users/add/address")
public class UsersAddAddressController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Users_address usersAddress = new Users_address();
        usersAddress.setUsersID(Integer.parseInt(request.getParameter("UsersID")));
        usersAddress.setAddressDetails(request.getParameter("AddressDetails"));
        usersAddress.setLabel(request.getParameter("Label"));
        UsersAddressServiceImpl impl = new UsersAddressServiceImpl();
        impl.save(usersAddress);
        impl.getSqlSession().close();
        R r = R.success("添加成功");
        PrintWriter out  = response.getWriter();
        out.write(JSONUtil.toJsonStr(r));

    }
}
